#pragma once

#include <pthread.h>
// 实现对锁的封装

class Mutex
{
public:
    Mutex(pthread_mutex_t *lock) : _lock(lock)
    {
    }
    ~Mutex()
    {
    }

    void Lock() { pthread_mutex_lock(_lock); }
    void UnLock() { pthread_mutex_unlock(_lock); }

private:
    pthread_mutex_t *_lock;
};

class LockGuard
{
public:
    LockGuard(pthread_mutex_t *lock) : _mutex(lock)
    {
        _mutex.Lock();
    }
    ~LockGuard()
    {
        _mutex.UnLock();
    }

private:
    Mutex _mutex;
};